package com.chen.web;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/userServlet")
public class UserServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取请求中数据
        String username = req.getParameter("username");
        String info = "<h1>YES</h1>";
        if ("chen".equals(username)) {
            info = "NO";
        }
        // 设置返回的报文数据
        // 设置响应的报文头的中content-Type的作用是:告知浏览器以什么形式来解析响应报头的数据 (默认是以html的来进行解析)
        // 如果是静态资源content-Type 的设置是由tomcat通过查询 conf/web.xml文件中根据文件的拓展名来进行设置的
        resp.setHeader("Content-Type", "text/html");
        PrintWriter writer = resp.getWriter();
        writer.write(info);


    }
}
